package cn.tedu.imop.content.service.impl;

import cn.tedu.imop.common.pojo.PageData;
import cn.tedu.imop.content.dao.repository.ArticleCategoryRepository;
import cn.tedu.imop.content.entity.ArticleCategory;
import cn.tedu.imop.content.service.ArticleCategoryService;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

@Service
public class ArticleCategoryServiceImpl implements ArticleCategoryService {
    private final ArticleCategoryRepository articleCategoryRepository;

    public ArticleCategoryServiceImpl(ArticleCategoryRepository articleCategoryRepository) {
        this.articleCategoryRepository = articleCategoryRepository;
    }
    @Override
    public Boolean createArticleCategory(ArticleCategory articleCategory) {
        articleCategoryRepository.insertArticleCategory(articleCategory);
        return true;
    }

    @Override
    public PageData<ArticleCategory> getArticleCategoryList(ArticleCategory articleCategory) {
        return articleCategoryRepository.selectArticleCategoryList(articleCategory);
    }
    @Override
    public List<ArticleCategory> getArticleCategoryList() {
        List<ArticleCategory> articleCategories =
                articleCategoryRepository.selectArticleCategoryList();
        return articleCategories.stream()
                .filter(articleCategory -> articleCategory.getLevel() == 2)
                .collect(Collectors.toList());
    }
}
